<ui:composition
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:cc="http://java.sun.com/jsf/composite/cc"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        template="/resources/layout/common-layout.xhtml">

    <ui:define name="demoSampleParameters">
    </ui:define> 
    <ui:define name="head">
    </ui:define>
    <ui:define name="toolbar">
        <cc:toolbar bean="#{coursesController}" />
    </ui:define>
    <ui:define name="content">
        <p:growl id="growl" showDetail="true" showSummary="true" globalOnly="true"/>
        <h:form id="h2" prependId="false">
            <p:panel>
                <h:panelGrid columns="1" style="width:100%">
                <cc:courseForm
                        bean="#{coursesController.dataModel.selected.object}"
                        readonly="#{!coursesController.dataModel.selected.editable}"
                        durationTypes="#{coursesController.durationTypes}"
                        trainingProviders="#{coursesController.trainingProviders}"
                        contentTypes="#{coursesController.contentTypes}"
                        categories="#{coursesController.categories}"
                />
                <p:fieldset legend="#{msgs['pnl.messages']}">
                    <h:panelGrid id="modify_messages" columns="1">
                        <p:messages id="m1" showDetail="true" showSummary="false" globalOnly="false"  />
                    </h:panelGrid>
                </p:fieldset>
                <h:panelGrid id="modify_buttons" columns="3" cellpadding="4" rendered="#{coursesController.inConversation}">
                    <p:commandButton
                            id="b1"
                            value="#{msgs['btn.save']}"
                            icon="ui-icon-disk"
                            actionListener="#{coursesController.dataModel.onSave}"
                            ajax="true"
                            oncomplete="onSaveComplete(xhr, status, args, modifyDialogVar, 1)"
                            update="modify_messages display_messages"
                            rendered="#{coursesController.dataModel.selected.editable}"
                            />

                    <p:commandButton
                            id="b4"
                            value="#{msgs['btn.delete']}"
                            icon="ui-icon-minus"
                            actionListener="#{coursesController.dataModel.onDelete}"
                            ajax="true"
                            rendered="#{coursesController.dataModel.selected.object.id ne null and coursesController.dataModel.selected.editable}"
                            oncomplete="onDeleteComplete(xhr, status, args, modifyDialogVar, 1)"
                            update="modify_messages display_messages"
                            />

                    <p:commandButton
                            id="b3"
                            icon="ui-icon-close"
                            value="#{msgs['btn.back']}"
                            action="#{coursesController.onCompleteConversation}"
                            ajax="false"
                            immediate="true"
                            update="modify_messages"
                            />
                </h:panelGrid>
            </h:panelGrid>
            </p:panel>
        </h:form>
        <h:form id="h3" prependId="false">
            <p:dialog
                    id="messageDialog"
                    header="#{msgs['dlg.training.course']}"
                    widgetVar="modifyDialogVar"
                    resizable="false"
                    width="400"
                    modal="true"
                    showEffect="explode"
                    hideEffect="explode">
                <p:fieldset legend="#{msgs['pnl.messages']}">
                    <h:panelGrid id="display_messages" columns="1">
                        <h:outputText value="#{msgs['msg.training.course.saved']}" />
                    </h:panelGrid>
                </p:fieldset>
                <h:panelGrid id="display_buttons" columns="3" cellpadding="4">
                    <p:commandButton
                            id="b10"
                            icon="ui-icon-close"
                            value="#{msgs['btn.ok']}"
                            action="#{coursesController.onCompleteConversation}"
                            ajax="false"
                            immediate="true"
                            />
                </h:panelGrid>
            </p:dialog>
        </h:form>
    </ui:define>
</ui:composition>